package com.gxa.logistics.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.common.util.PageResultUtil;
import com.gxa.logistics.domain.dto.*;
import com.gxa.logistics.domain.vo.ItemsVO;
import com.gxa.logistics.domain.vo.SpareVO;
import com.gxa.logistics.mapper.SpareMapper;
import com.gxa.logistics.service.SpareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpareServiceImpl implements SpareService {
    @Autowired
    private SpareMapper spareMapper;

    @Override
    public RespResult<PageWrapperDTO<SpareVO>> list(SpareoReqListDTO spareoReqListDTO) {
        PageHelper.startPage(spareoReqListDTO.getPageNo(), spareoReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<SpareVO> pageCommon = new PageWrapperDTO<>();
        List<SpareVO> spareList = spareMapper.findSpareByDisStatus(spareoReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(spareList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public RespResult<PageWrapperDTO<SpareVO>> list(SparetReqListDTO sparetReqListDTO) {
        PageHelper.startPage(sparetReqListDTO.getPageNo(), sparetReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<SpareVO> pageCommon = new PageWrapperDTO<>();
        List<SpareVO> spareList = spareMapper.findSpareByDisStatus1(sparetReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(spareList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void updateSpare1(Integer item_num) {
            spareMapper.updateSpare1(item_num);
    }

    @Override
    public void updateSpare2(Integer item_num) {
            spareMapper.updateSpare2(item_num);
    }

    @Override
    public RespResult<PageWrapperDTO<SpareVO>> list(SpareReqListDTO spareReqListDTO) {
        // 使用分页插件
        PageHelper.startPage(spareReqListDTO.getPageNo(), spareReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<SpareVO> pageCommon = new PageWrapperDTO<>();
        List<SpareVO> spareList = spareMapper.findSpareByWhere(spareReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(spareList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void insertSpare(SpareSaveDTO spareSaveDTO) {
        spareMapper.insertSpare(spareSaveDTO);
    }

    @Override
    public void updateSpare(SpareUpdateDTO spareUpdateDTO) {
        spareMapper.updateSpare(spareUpdateDTO);
    }

    @Override
    public void deleteSpareByitemName(String item_name) {
        spareMapper.deleteSpareByitemName(item_name);
    }
}
